﻿var prefs = new _IG_Prefs();
var twUserName = prefs.getString("twitterUserName");
var twPassword = prefs.getString("twitterPassword");

function init() {
    var curView = gadgets.views.getCurrentView().getName();
    if (curView == "canvas") {
        initCanvas();       
    }
    else
        if (curView == "profile") {
            initProfile();
    }
    else {
        alert("Nem támogatott nézet.");
    }
}

function initCanvas() {
}

function initProfile() {
    var userName = document.getElementById('tbUserName');
    var password = document.getElementById('tbPassword');
    var passwordAgain = document.getElementById('tbPasswordAgain');

    userName.value = twUserName;
    password.value = twPassword;
    passwordAgain.value = twPassword;
}

function storeProfile(tbUserName, tbPassword, tbPasswordAgain) {
    var userName = document.getElementById('tbUserName').value;
    var password = document.getElementById('tbPassword').value;
    var passwordAgain = document.getElementById('tbPasswordAgain').value;

    if (password !== passwordAgain) {
        alert('Nem egyezik!');
        return false;
    }

    prefs.set("twitterUserName", twUserName = userName);
    prefs.set("twitterPassword", twPassword = password);
}

gadgets.util.registerOnLoadHandler(init);
